﻿<phone:PhoneApplicationPage x:Class="WinSource.Views.SettingsPage"
                            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                            xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
                            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                            xmlns:Controls="clr-namespace:WinSource.Controls"
                            xmlns:Converters="clr-namespace:DotNetApp.Toolkit.Converters;assembly=DotNetApp.Toolkit"
                            DataContext="{Binding SettingsViewModel, Source={StaticResource Locator}}"
                            mc:Ignorable="d"
                            d:DesignHeight="800"
                            d:DesignWidth="480">

  <phone:PhoneApplicationPage.Resources>

        <Converters:VisibilityConverter x:Key="VisibilityConverter" />

        <Style x:Key="GridStyle"
           TargetType="Grid">
      <Setter Property="Background"
              Value="{StaticResource BackgroundColor}" />
    </Style>

    <Style x:Key="TitleControlStyle"
           TargetType="Controls:TitleControl">
      <Setter Property="Background"
              Value="Black" />
      <Setter Property="TitleName"
              Value="{StaticResource ApplicationName}" />
    </Style>

    <Style x:Key="CheckBoxStyle"
           TargetType="CheckBox">
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="CheckBox">
            <Grid Background="Transparent">
              <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
                  <VisualState x:Name="Normal" />
                  <VisualState x:Name="MouseOver" />
                  <VisualState x:Name="Pressed">
                    <Storyboard>
                      <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckBackground"
                                                     Storyboard.TargetProperty="Background">
                        <DiscreteObjectKeyFrame KeyTime="0"
                                                Value="White" />
                      </ObjectAnimationUsingKeyFrames>
                      <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckBackground"
                                                     Storyboard.TargetProperty="BorderBrush">
                        <DiscreteObjectKeyFrame KeyTime="0"
                                                Value="White" />
                      </ObjectAnimationUsingKeyFrames>
                      <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckMark"
                                                     Storyboard.TargetProperty="Fill">
                        <DiscreteObjectKeyFrame KeyTime="0"
                                                Value="White" />
                      </ObjectAnimationUsingKeyFrames>
                      <ObjectAnimationUsingKeyFrames Storyboard.TargetName="IndeterminateMark"
                                                     Storyboard.TargetProperty="Fill">
                        <DiscreteObjectKeyFrame KeyTime="0"
                                                Value="White" />
                      </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                  </VisualState>
                </VisualStateGroup>
                <VisualStateGroup x:Name="CheckStates">
                  <VisualState x:Name="Checked">
                    <Storyboard>
                      <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckMark"
                                                     Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="0">
                          <DiscreteObjectKeyFrame.Value>
                            <Visibility>Visible</Visibility>
                          </DiscreteObjectKeyFrame.Value>
                        </DiscreteObjectKeyFrame>
                      </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                  </VisualState>
                  <VisualState x:Name="Unchecked" />
                  <VisualState x:Name="Indeterminate">
                    <Storyboard>
                      <ObjectAnimationUsingKeyFrames Storyboard.TargetName="IndeterminateMark"
                                                     Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="0">
                          <DiscreteObjectKeyFrame.Value>
                            <Visibility>Visible</Visibility>
                          </DiscreteObjectKeyFrame.Value>
                        </DiscreteObjectKeyFrame>
                      </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                  </VisualState>
                </VisualStateGroup>
              </VisualStateManager.VisualStateGroups>
              <Grid>
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="32" />
                  <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Border x:Name="CheckBackground"
                        IsHitTestVisible="False"
                        VerticalAlignment="Center"
                        HorizontalAlignment="Left"
                        Background="{StaticResource RedBrush}"
                        BorderBrush="{StaticResource RedBrush}"
                        Height="32"
                        Width="32" />
                <Rectangle x:Name="IndeterminateMark"
                           IsHitTestVisible="False"
                           Width="16"
                           Height="16"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           Visibility="Collapsed"
                           Grid.Row="0" />
                <Path x:Name="CheckMark"
                      IsHitTestVisible="False"
                      Visibility="Collapsed"
                      Width="24"
                      Height="18"
                      Stretch="Fill"
                      HorizontalAlignment="Center"
                      VerticalAlignment="Center"
                      Fill="White"
                      Data="M0,119 L31,92 L119,185 L267,0 L300,24 L122,250 z"
                      StrokeLineJoin="Round"
                      StrokeThickness="2" />
                <ContentControl x:Name="ContentContainer"
                                Grid.Column="1"
                                Content="{TemplateBinding Content}"
                                ContentTemplate="{TemplateBinding ContentTemplate}"
                                Margin="12,0,0,0"
                                HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                Padding="{TemplateBinding Padding}"
                                Foreground="{TemplateBinding Foreground}" />
              </Grid>
            </Grid>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>


  </phone:PhoneApplicationPage.Resources>

  <Grid Style="{StaticResource GridStyle}">

    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
      <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

    <Controls:TitleControl Style="{StaticResource TitleControlStyle}"
                           PageName="settings" />

    <StackPanel Grid.Row="1"
                DataContext="{Binding Settings}"
                Margin="24,0">

      <CheckBox Foreground="Black"
                IsChecked="{Binding IsDownloadingArticlesOffline, Mode=TwoWay}"
                Margin="0,0,0,12"
                Style="{StaticResource CheckBoxStyle}">

        <TextBlock Text="Periodically download articles in the background if the Internet connection is Wi-Fi or Ethernet"
                   TextWrapping="Wrap" />

      </CheckBox>

      <CheckBox Foreground="Black"
                IsChecked="{Binding IsToastNotificationUsed, Mode=TwoWay}"
                Margin="0,12"
                Style="{StaticResource CheckBoxStyle}"
                Visibility="{Binding IsDownloadingArticlesOffline, Converter={StaticResource VisibilityConverter}}">

        <TextBlock Text="Show toast notification when new articles are available"
                   TextWrapping="Wrap" />

      </CheckBox>

      <CheckBox Foreground="Black"
                IsChecked="{Binding IsRefreshAutomatic, Mode=TwoWay}"
                Margin="0,12,0,0"
                Style="{StaticResource CheckBoxStyle}">

        <TextBlock Text="Automatic refresh when the application launches"
                   TextWrapping="Wrap" />

      </CheckBox>

    </StackPanel>

  </Grid>

</phone:PhoneApplicationPage>